<template>
  <vue-ueditor-wrap
    ref="ueditor"
    v-model="currentValue"
    class="vue-ueditor-wrap"
    :config="currentConfig"
    :destroy="true"
    :init="init"
  />
</template>

<script>
// 参考 https://github.com/HaoChuan9421/vue-ueditor-wrap
import VueUeditorWrap from 'vue-ueditor-wrap'
import Config from './ueditor.config'

export default {
  name: 'Index',
  components: { VueUeditorWrap },
  props: {
    value: {
      type: String,
      default: ''
    },
    config: {
      type: Object,
      default: () => {
      }
    }
  },
  data () {
    return {
      currentValue: ''
    }
  },
  computed: {
    currentConfig () {
      return Object.assign({}, Config, this.config)
    }
  },
  watch: {
    // 对外提供 v-model
    value: {
      handler (val) {
        if (this.currentValue !== val) {
          this.currentValue = val
        }
      },
      immediate: true
    },
    // 对外提供 v-model
    currentValue (val) {
      this.$emit('input', val)
      this.$emit('change', val)
    }
  },
  methods: {
    init () {
    }
  }
}
</script>

<style lang="scss">
  .vue-ueditor-wrap {
    line-height: normal;
  }
</style>
